// import { Query } from "@nestjs/common";
import { Controller, Get, Req, Request, Query, Headers, Post, Body, Response, Next, Inject } from "@nestjs/common";
import type { ExpressRequest } from "express";
import { User } from "./user.decorator";
import { AppService } from "./app.service";
import { CoreService } from "./core/core.service";

@Controller("app")
export class AppController {
  constructor(
    private appService: AppService,
    private coreService: CoreService,
    @Inject("TOKEN") private readonly token: string,
    @Inject("TOKEN11") private readonly token1: string
  ) {}
  @Get("index")
  index(@Request() p1: ExpressRequest, name: string, @Req() p2: ExpressRequest) {
    console.log(p1.method);
    console.log(p2.url);
    return 123;
  }

  @Get("aaaa")
  test() {
    console.log(this.token, this.token1);
    console.log(this.appService.getHello());
    console.log(this.coreService.getHello());
    return "aaaaa";
  }

  @Get("query")
  testQuery(@Query() q, @Query("id") id: any) {
    console.log(q, id);
    return "aaaaa";
  }

  @Get("h")
  testH(@Headers() h, @Headers("accept") a) {
    console.log(h, a);
    return "aaaaa";
  }

  @Post("post")
  testP(@Body() body) {
    console.log(body);
    return "aaaaa";
  }

  @Get("res")
  testRes(@Response({ passthrough: true }) res) {
    // res.json(123);
    return 1111;
  }

  @Get("next")
  testNext(@Next() next, @Response({ passthrough: true }) res) {
    // res.json(123);
    next();
    return 123;
  }

  @Get("user")
  testUser(@User() user) {
    return user;
  }
}
